TaskWindow = function () {
  TaskWindow.superclass.constructor.call(this)
  this.initControls()
  this.initEvents()
}
mini.extend(TaskWindow, mini.Window, {
  url: mini_JSPath + '../plusproject/js/TaskWindow.html',
  width: 720,
  height: 480,
  showFooter: true,
  showModal: true,
  initControls: function () {
    // body
    var bodyEl = this.getBodyEl()
    mini.update(this.url, bodyEl)

    // footer buttons
    var footerEl = this.getFooterEl()
    mini.setStyle(footerEl, 'padding:8px;padding-right:10px;text-align:right;')
    footerEl.innerHTML = '<a name="ok" class="mini-button" width="60" style="margin-right:10px;">确定</a> <a name="cancel" class="mini-button" width="60">取消</a>'
    mini.parse(footerEl)

    // 获取控件对象

    this.ok = mini.getbyName('ok', this)
    this.cancel = mini.getbyName('cancel', this)

    this.addLink = mini.get('twin_linkadd')
    this.delLink = mini.get('twin_linkdel')
    this.addRes = mini.get('twin_resadd')
    this.delRes = mini.get('twin_resdel')
    this.addEqu = mini.get('twin_equadd')
    this.delEqu = mini.get('twin_equdel')
    this.addPlanWork = mini.get('twin_planworkadd')
    this.delPlanWork = mini.get('twin_planworkdel')

    this.Name = mini.get('twin_name')
    this.Principal = mini.get('twin_principal')
    this.PercentComplete = mini.get('twin_percentcomplete')
    this.Department = mini.get('twin_department')
    this.Duration = mini.get('twin_duration')
    this.Work = mini.get('twin_work')
    this.Start = mini.get('twin_start')
    this.Finish = mini.get('twin_finish')
    this.ActualStart = mini.get('twin_actualstart')
    this.ActualFinish = mini.get('twin_actualfinish')
    this.PredecessorLink = mini.get('twin_linkgrid')
    this.Assignments = mini.get('twin_resgrid')
    this.Equgrid = mini.get('twin_equgrid')
    this.Planworkgrid = mini.get('twin_planworkgrid')
    this.ConstraintType = mini.get('twin_constrainttype')
    this.ConstraintDate = mini.get('twin_constraintdate')
    this.FixedDate = mini.get('twin_fixeddate')
    this.Milestone = mini.get('twin_milestone')
    this.Critical2 = mini.get('twin_critical2')
    this.WBS = mini.get('twin_wbs')
    this.Notes = mini.get('twin_notes')
    this.leftTree = mini.get('twin_leftTree')
    this.PlanStart = ''
    this.PlanFinish = ''
    this.Reloadelement = mini.get('twin_Reload')

    //
    this.planworktree = mini.get('planworktree')
  },
  initEvents: function () {
    // 实际开始时间事件
    this.ActualStart.on('valuechanged', function () {
      var start = this.ActualStart.getValue()
      this.Start.setValue(start)
      var finish = this.Finish.getValue()
      var start = this.Start.getValue()
      var duration = this.project.getDurationByCalendar(start, finish)
      this.Duration.setValue(duration)
      this.Start.disable()
    }, this)
    // 实际完成时间事件
    this.ActualFinish.on('valuechanged', function () {
      var actualFinish = this.ActualFinish.getValue()
      this.Finish.setValue(actualFinish)
      var finish = this.Finish.getValue()
      var start = this.Start.getValue()
      var duration = this.project.getDurationByCalendar(start, finish)
      this.Duration.setValue(duration)
      this.Finish.disable()
    }, this)

    // 绑定事件处理函数

    /// ///////////////////////////
    this.Department.on('ValueChanged', function () {
      this.Principal.setData(this.getPrincipalsByDepartment(this.Department.getValue()))
      this.Principal.setValue('')
    }, this)
    /// //////////////////////////
    this.Duration.on('valuechanged', function (e) {
      if (this.dateChangedAction != null) return

      this.dateChangedAction = 'duration'
      var start = this.Start.getValue()
      var duration = this.Duration.getValue()
      if (start) {
        var date = this.project.getFinishByCalendar(start, duration)
        this.Finish.setValue(date)
      }
      this.dateChangedAction = null
    }, this)
    this.Start.on('valuechanged', function (e) {
      if (this.dateChangedAction != null) return
      this.dateChangedAction = 'start'
      var start = this.Start.getValue()
      var duration = this.Duration.getValue()
      if (start) {
        var date = this.project.getFinishByCalendar(start, duration)
        this.Finish.setValue(date)
      }
      this.dateChangedAction = null
    }, this)
    this.Finish.on('valuechanged', function (e) {
      if (this.dateChangedAction != null) return

      this.dateChangedAction = 'finish'
      var finish = this.Finish.getValue()
      var start = this.Start.getValue()
      if (finish && start) {
        if (start > finish) {
          start = finish
          this.Start.setValue(start)
        }
        var duration = this.project.getDurationByCalendar(start, finish)
        this.Duration.setValue(duration)
      }
      this.dateChangedAction = null
    }, this)

    /// /////////////////////////
    // 重新加载构建绑定事件
    this.Reloadelement.on('click', function (e) {
      if (confirm('是否确定要重新加载关联构件数据？') == true) {
        var ele = mini.clone(this.task.ElementListNew) || []
        this.leftTree.setData(ele)
        /// 获取构件应反回任务的时间
        var elementList = mini.clone(this.leftTree.getData())
        var iii = 0
        var planstart
        var planfinish
        var start
        var finish
        var actualstart
        var actualfinish
        elementList.forEach(function (o) {
          if (iii == 0) {
            planstart = o.PlanStartDate
            planfinish = o.PlanEndDate
            start = o.StartDate
            finish = o.EndDate
            actualstart = o.ActualStartDate
            actualfinish = o.ActualEndDate
          }
          if ((o.PlanStartDate != null && planstart == null) || (o.PlanStartDate != null && planstart != null && o.PlanStartDate < planstart)) {
            planstart = o.PlanStartDate
          }
          if ((o.PlanEndDate != null && planfinish == null) || (o.PlanEndDate != null && planfinish != null && o.PlanEndDate > planfinish)) {
            planfinish = o.PlanEndDate
          }
          if ((o.StartDate != null && start == null) || (o.StartDate != null && start != null && o.StartDate < start)) {
            start = o.StartDate
          }
          if ((o.EndDate != null && finish == null) || (o.EndDate != null && finish != null && o.EndDate > finish)) {
            finish = o.EndDate
          }
          if ((o.ActualStartDate != null && actualstart == null) || (o.ActualStartDate != null && actualstart != null && o.ActualStartDate < actualstart)) {
            actualstart = o.ActualStartDate
          }
          if ((o.ActualEndDate != null && actualfinish != null && o.ActualEndDate > actualfinish)) {
            actualfinish = o.ActualEndDate
          } else if (o.ActualEndDate == null || actualfinish == null) {
            actualfinish = null
          }
          iii += 1
        })

        this.Start.setValue(start)
        this.Finish.setValue(finish)
        this.Duration.setValue(parseInt(Math.abs(finish - start) / 1000 / 60 / 60 / 24) + 1) // 把相差的毫秒数转换为天数
        this.ActualStart.setValue(actualstart)
        this.ActualFinish.setValue(actualfinish)
        this.PlanStart = planstart
        this.PlanFinish = planfinish
      }
    }, this)
    this.addLink.on('click', function (e) {
      if (!this.ActualStart || this.ActualStart.value == '') {
        var link = {
          Type: 1,
          LinkLag: 0
        }
        this.PredecessorLink.addRow(link)
      }
    }, this)
    this.delLink.on('click', function (e) {
      if (!this.ActualStart || this.ActualStart.value == '') {
        this.PredecessorLink.removeSelected()
      }
    }, this)
    this.PredecessorLink.on('drawcell', function (e) {
      var link = e.record
      var field = e.field
      var preTask = this.getTaskByUID(link.PredecessorUID) || {}
      if (field == 'PredecessorID') {
        e.cellHtml = preTask.ID
      }
      if (field == 'PredecessorName') {
        e.cellHtml = preTask.Name
      }
      if (field == 'Type') {
        var linkType = mini.Gantt.PredecessorLinkType[e.value]
        e.cellHtml = linkType.Name
      }
      if (field == 'LinkLag') {
        e.cellHtml = e.value + '天'
      }
    }, this)
    this.PredecessorLink.on('cellbeginedit', function (e) {
      var link = e.record
      var field = e.field
      var preTask = this.getTaskByUID(link.PredecessorUID) || {}
      if (e.field == 'PredecessorID') {
        e.value = preTask.ID || ''
      }
      if (e.field == 'Type') {
        e.editor.setData(mini.Gantt.PredecessorLinkType)
      }
      if (this.ActualStart && this.ActualStart.value != '') {
        e.cancel = true
      }
    }, this)
    this.PredecessorLink.on('cellcommitedit', function (e) {
      if (e.field == 'PredecessorID') {
        // e.editor.setData(mini.Gantt.PredecessorLinkType);
        e.cancel = true

        var task = this.getTaskByID(e.value)
        if (task) {
          e.sender.updateRow(e.record, 'PredecessorUID', task.UID)
        } else {
          e.sender.updateRow(e.record, 'PredecessorUID', '')
        }
      }
    }, this)
    /// //////////////////////////////
    this.addRes.on('click', function (e) {
      var align = {
        Units: 1
      }
      this.Assignments.addRow(align)
    }, this)
    this.delRes.on('click', function (e) {
      this.Assignments.removeSelected()
    }, this)

    // 关联设备新增和删除
    this.addEqu.on('click', function (e) {
      var align = {
        Units: 1
      }
      this.Equgrid.addRow(align)
    }, this)
    this.delEqu.on('click', function (e) {
      this.Equgrid.removeSelected()
    }, this)

    // 关联工种
    this.addPlanWork.on('click', function (e) {
      var align = {
        Number: 0,
        WName: ''
      }
      this.Planworkgrid.addRow(align)
      // this.planworktree.setData(this.getPlanwork());
    }, this)
    this.delPlanWork.on('click', function (e) {
      this.Planworkgrid.removeSelected()
    }, this)
    var me = this

    this.Assignments.on('drawcell', function (e) {
      var ass = e.record
      var field = e.field
      var re = me.getResourceByUID(ass.ResourceUID)
      if (!re) return

      if (field == 'ResourceUID') {
        e.cellHtml = re.Name
      }
      if (field == 'Units') {
        if (re.Type == 1) {
          e.cellHtml = parseInt(e.value * 100) + '%'
        } else {
          if (re.Type == 2) {
            e.cellHtml = ''
          } else {
            e.cellHtml = e.value
          }
        }
      }
    }, this)

    // 关联设备操作单元格
    this.Equgrid.on('drawcell', function (e) {
      var ass = e.record
      var field = e.field
      var re = me.getPlequipmentByUID(ass.ResourceUID)
      if (!re) return
      if (field == 'ResourceUID') {
        e.cellHtml = re.Specifications
        ass.Number = re.Number
      }
      if (field == 'EName') {
        e.cellHtml = re.EName
      }
      if (field == 'TypeName') {
        e.cellHtml = re.TypeName
      }
      if (field == 'TypeCode') {
        e.cellHtml = re.TypeCode
      }
      if (field == 'EquipmentSource') {
        e.cellHtml = re.EquipmentSource
      }
      if (field == 'Number') {
        e.cellHtml = re.Number
      }
    }, this)
    this.Equgrid.on('cellbeginedit', function (e) {
      var record = e.record
      var resource = me.getPlequipmentByUID(record.ResourceUID)

      if (e.field == 'ResourceUID') {
        e.editor.setData(this.getPlequipment())
      } else {
        if (!resource) {
          e.cancel = true
        }
      }
    }, this)
    // 关联工种操作单元格
    this.Planworkgrid.on('drawcell', function (e) {
      var ass = e.record
      var field = e.field
      var re = me.getPWorkByUID(ass.planworkUID)
      if (!re) return
      if (field == 'planworkUID') {
        e.cellHtml = re.Name
        ass.WName = re.Name
      }
      if (field == 'Unit') {
        e.cellHtml = e.value
        if (e.cellHtml == '' || e.cellHtml == null || e.cellHtml == undefined) {
          e.cellHtml = re.Unit
        }
      }
      if (field == 'Remark') {
        e.cellHtml = e.value
      }
      if (field == 'Number') {
        e.cellHtml = e.value
      }
      if (field == 'WName') {
        e.cellHtml = re.Name
      }
    }, this)
    this.Planworkgrid.on('cellbeginedit', function (e) {
      var record = e.record
      var resource = me.getPWorkByUID(record.planworkUID)
      debugger
      if (e.field == 'planworkUID') {
        e.editor.setData(this.getPlanwork())
      }
      if (e.field == 'Number') {
        // e.cancel = true;
      }
    }, this)

    this.Assignments.on('cellbeginedit', function (e) {
      var record = e.record
      var resource = me.getResourceByUID(record.ResourceUID)

      if (e.field == 'ResourceUID') {
        e.editor.setData(this.getResources())
      } else {
        if (!resource) {
          e.cancel = true
          return
        }
      }

      if (e.field == 'Units') {
        if (resource.Type == 2) {
          e.cancel = true
        }
        if (resource.Type == 1) {
          e.value = e.value * 100
        }
      }
      if (e.field == 'Cost') {
        if (resource.Type != 2) {
          e.cancel = true
        }
      }
    }, this)

    this.Assignments.on('cellcommitedit', function (e) {
      var record = e.record
      var resource = me.getResourceByUID(record.ResourceUID)

      if (!resource) return

      if (e.field == 'Units') {
        if (resource.Type == 1) {
          // e.value = NumberUtil.toFixed(parseFloat(e.value / 100), 2);

          var num = parseFloat(e.value / 100)

          e.value = num
        }
      }
    })

    this.Assignments.on('cellendedit', function (e) {
      var record = e.record
      var resource = this.getResourceByUID(record.ResourceUID)
      if (!resource) return

      if (resource.Type != 2) {
        var Cost = record.Units * resource.Cost
        me.Assignments.updateRow(record, {
          Cost: Cost
        })
      }

      //            if (e.field == "ResourceUID") {
      //                e.editor.setData(this.getResources());
      //            }
      //            if (e.field == 'Units') {
      //                if (resource.Type == 2) {
      //                    e.cancel = true;
      //                }
      //                if (resource.Type == 0) {
      //
      //                }
      //            }
      //            if (e.field == 'Cost') {
      //                if (resource.Type != 2) {
      //                    e.cancel = true;
      //                }
      //            }
    }, this)

    /// ///////(构件)自定义
    this.leftTree.on('drawcell', function (e) {
      var ass = e.record
      var field = e.field
      var value = e.value
      // 格式化日期
      if (field == 'PlanStartDate' || field == 'PlanEndDate' || field == 'StartDate' || field == 'EndDate' || field == 'ActualStartDate' || field == 'ActualEndDate') {
        if (mini.isDate(value)) e.cellHtml = mini.formatDate(value, 'yyyy-MM-dd')
      }
    }, this)
    this.leftTree.on('cellendedit', function (e) {
      var ass = e.record
      var field = e.field
      var value = e.value
      if (field == 'ActualStartDate') {
        if (value) ass.StartDate = value
        else ass.ActualEndDate = value
      }
      if (field == 'ActualEndDate') {
        if (value) ass.EndDate = value
      }
      if (ass.ActualStartDate > ass.EndDate) {
        ass.EndDate = ass.StartDate
        ass.ActualEndDate = ass.StartDate
      }
      this.leftTree.setData(e.source.data)
      /// 获取构件应反回任务的时间
      var elementList = mini.clone(this.leftTree.getData())
      var iii = 0
      var planstart
      var planfinish
      var start
      var finish
      var actualstart
      var actualfinish
      elementList.forEach(function (o) {
        if (iii == 0) {
          planstart = o.PlanStartDate
          planfinish = o.PlanEndDate
          start = o.StartDate
          finish = o.EndDate
          actualstart = o.ActualStartDate
          actualfinish = o.ActualEndDate
        }
        if ((o.PlanStartDate != null && planstart == null) || (o.PlanStartDate != null && planstart != null && o.PlanStartDate < planstart)) {
          planstart = o.PlanStartDate
        }
        if ((o.PlanEndDate != null && planfinish == null) || (o.PlanEndDate != null && planfinish != null && o.PlanEndDate > planfinish)) {
          planfinish = o.PlanEndDate
        }
        if ((o.StartDate != null && start == null) || (o.StartDate != null && start != null && o.StartDate < start)) {
          start = o.StartDate
        }
        if ((o.EndDate != null && finish == null) || (o.EndDate != null && finish != null && o.EndDate > finish)) {
          finish = o.EndDate
        }
        if ((o.ActualStartDate != null && actualstart == null) || (o.ActualStartDate != null && actualstart != null && o.ActualStartDate < actualstart)) {
          actualstart = o.ActualStartDate
        }
        if ((o.ActualEndDate != null && actualfinish != null && o.ActualEndDate > actualfinish)) {
          actualfinish = o.ActualEndDate
        } else if (o.ActualEndDate == null || actualfinish == null) {
          actualfinish = null
        }
        iii += 1
      })

      this.Start.setValue(start)
      this.Finish.setValue(finish)
      this.Duration.setValue(parseInt(Math.abs(finish - start) / 1000 / 60 / 60 / 24) + 1) // 把相差的毫秒数转换为天数
      this.ActualStart.setValue(actualstart)
      this.ActualFinish.setValue(actualfinish)
      this.PlanStart = planstart
      this.PlanFinish = planfinish
      // }
    }, this)
    this.leftTree.on('cellbeginedit', function (e) {
      var task = e.record
      var column = e.column
      var field = e.field
      // if (field == 'PlanStartDate'&& !task.ActualStart) {
      //   e.cancel = true;
      // }
      // if (field == 'PlanEndDate') {
      //   e.cancel = true;
      // }
      if (task.elementid) {
        if (obj.bimEngine) {
          obj.bimEngine.getHighlightManager().clearHighlightElementList()
          obj.bimEngine.getHighlightManager().highlightElement(task.elementid)
        }
      }
      // if (field == 'ActualEndDate' && !task.ActualStartDate) {
      //   e.cancel = true;
      // }
      if (field == 'EndDate' && task.ActualEndDate) {
        e.cancel = true
      }
      if (field == 'StartDate' && task.ActualStartDate) {
        e.cancel = true
      }
    }, this)
    this.leftTree.on('cellcommitedit', function (e) {
      var field = e.field

      if (field == 'PlanStartDate' || field == 'PlanEndDate') {
        if (confirm('是否确定要修改基准计划？') == false) {
          e.cancel = true
        }
      }
    }, this)

    /// ///////////////////////
    this.FixedDate.on('checkedchanged', function (e) {
      this.editEnabled()
    }, this)
    /// ///////////////////////
    this.ok.on('click', function (e) {
      var ret = true
      if (this.callback) ret = this.callback('ok')
      if (ret !== false) {
        this.hide()
      }
    }, this)
    this.cancel.on('click', function (e) {
      var ret = true
      if (this.callback) ret = this.callback('cancel')
      if (ret !== false) {
        this.hide()
      }
    }, this)
    this.on('beforebuttonclick', function (e) {
      if (e.name == 'close') {
        e.cancel = true
        var ret = true
        if (this.callback) ret = this.callback('close')
        if (ret !== false) {
          this.hide()
        }
      }
    }, this)
  },
  // 如果是摘要任务, 并且不固定工期, 则禁止摘要任务操作日期(开始/完成/工期)
  editEnabled: function () {
    this.Duration.enable()
    this.Start.enable()
    this.Finish.enable()
    this.ConstraintType.enable()
    this.ConstraintDate.enable()
    this.FixedDate.disable()

    if (this.__TaskSummary) {
      this.FixedDate.enable()

      if (this.FixedDate.getChecked()) {
        this.ConstraintType.disable()
        this.ConstraintDate.disable()
      } else {
        this.Duration.disable(true)
        this.Start.disable(true)
        this.Finish.disable(true)
      }
    }

    if (this.ActualStart && this.ActualStart.value != '') {
      this.ConstraintType.disable()
      this.ConstraintDate.disable()
    }
  },
  activeTab: function (tabName) {
    var tabs = mini.get('twin_tabs')
    var tab = tabs.getTab(tabName)
    if (tab) {
      tabs.activeTab(tab)
    }
  },
  setData: function (task, project, callback) {
    //        var tabs = mini.get("twin_tabs");
    //        var tab = tabs.getTab("adv");
    //        tabs.updateTab(tab, { visible: false });  //可根据用户权限和操作场景，动态显示和隐藏tab
    //
    this.callback = callback
    this.task = task
    this.project = project
    this.dataProject = project.getData()

    // 部门、负责人
    this.Department.setData(this.getDepartments())
    this.Department.setValue(task.Department)
    this.Principal.setData(this.getPrincipalsByDepartment(this.Department.getValue()))
    this.Principal.setValue(task.Principal)

    // 常规
    this.Name.setValue(task.Name)
    this.PercentComplete.setValue(task.PercentComplete)
    this.Work.setValue(task.Work)

    // 日期
    this.dateChangedAction = 'no'
    this.Duration.setValue(task.Duration)
    this.Start.setValue(task.Start)
    this.Finish.setValue(task.Finish)
    this.ActualStart.setValue(task.ActualStart)
    this.ActualFinish.setValue(task.ActualFinish)
    this.dateChangedAction = null
    this.PlanStart = task.PlanStart
    this.PlanFinish = task.PlanFinish

    // 高级
    var ctypes = mini.Gantt.ConstraintType.clone()
    if (task.Summary) {
      for (var i = ctypes.length - 1; i >= 0; i--) {
        var ct = ctypes[i]
        if (ct.ID != 0 && ct.ID != 4 && ct.ID != 7) {
          ctypes.removeAt(i)
        }
      }
    }
    this.ConstraintType.setData(ctypes)
    this.ConstraintType.setValue(task.ConstraintType)
    this.ConstraintDate.setValue(task.ConstraintDate)
    this.FixedDate.setChecked(task.FixedDate == 1)
    this.Milestone.setChecked(task.Milestone == 1)
    this.Critical2.setChecked(task.Critical2 == 1)
    this.WBS.setValue(task.WBS)

    // 前置任务、资源分配
    this.PredecessorLink.setData(mini.clone(task.PredecessorLink) || [])

    var me = this
    var ass = mini.clone(task.Assignments) || []
    //        $.each(ass, function (index, o) {
    //            var re = me.getResourceByUID(o.ResourceUID);
    //            if(re && re.) o.Cost = re.
    //        });
    this.Assignments.setData(ass)

    var Equgrid = mini.clone(task.Equgrid) || []
    this.Equgrid.setData(Equgrid)

    var Planworkgrid = mini.clone(task.Planworkgrid) || []
    this.Planworkgrid.setData(Planworkgrid)
    this.Notes.setValue(task.Notes)
    var ele = mini.clone(task.ElementList) || []
    this.leftTree.setData(ele)
    // 保存初始化的任务开始日期(点击"确定", 判断此值是否变化, 如果变化, 且没有设置任务限制, 则自动设置任务限制)
    this.__TaskStart = task.Start ? new Date(task.Start.getTime()) : null
    this.__TaskSummary = task.Summary == 1

    // 控件可操作性处理
    this.editEnabled()

    // 设置日期选择框的显示日期为项目开始日期，方便操作
    var startDate = this.dataProject.StartDate
    this.Start.setViewDate(startDate)
    this.Finish.setViewDate(startDate)
    this.ConstraintDate.setViewDate(startDate)
    this.ActualStart.setViewDate(startDate)
    this.ActualFinish.setViewDate(startDate)

    // 初始化开始时间状态 根据实际时间
    var actualStart = this.ActualStart.getValue()
    if (actualStart) {
      this.Start.disable()
    }
    var actualFinish = this.ActualFinish.getValue()
    if (actualFinish) {
      this.Finish.disable()
      this.Duration.disable()
    }
  },
  getData: function () {
    var task = {
      DateChangeAction: this.DateChangeAction,

      Name: this.Name.getValue(),
      Department: this.Department.getValue(),
      Principal: this.Principal.getValue(),

      PercentComplete: this.PercentComplete.getValue(),
      Duration: this.Duration.getValue(),
      Work: this.Work.getValue(),

      Start: this.Start.getValue(),
      Finish: this.Finish.getValue(),

      ActualStart: this.ActualStart.getValue(),
      ActualFinish: this.ActualFinish.getValue(),

      PlanStart: this.PlanStart,
      PlanFinish: this.PlanFinish,

      ConstraintType: this.ConstraintType.getValue(),
      ConstraintDate: this.ConstraintDate.getValue(),
      Notes: this.Notes.getValue(),
      WBS: this.WBS.getValue(),

      FixedDate: this.FixedDate.getChecked() ? 1 : 0,
      Milestone: this.Milestone.getChecked() ? 1 : 0,
      Critical2: this.Critical2.getChecked() ? 1 : 0

    }

    // 资源分配
    task.Assignments = mini.clone(this.Assignments.getData())
    // 关联设备
    task.Equgrid = mini.clone(this.Equgrid.getData())
    // 关联工种
    task.Planworkgrid = mini.clone(this.Planworkgrid.getData())
    debugger
    // 前置任务
    task.PredecessorLink = mini.clone(this.PredecessorLink.getData())
    // （构件）自定义
    task.ElementList = mini.clone(this.leftTree.getData())
    // 日期范围
    if (task.Start) { // 开始日期是:   00:00:00
      var d = task.Start
      task.Start = new Date(d.getFullYear(), d.getMonth(), d.getDate())
    }
    if (task.Finish) { // 完成日期是:   23:23:59
      var d = task.Finish
      task.Finish = new Date(d.getFullYear(), d.getMonth(), d.getDate(), 23, 59, 59)
    }

    // 任务限制        --去掉
    // if (task.ConstraintType == 0 || task.ConstraintType == 1) {
    //   task.ConstraintDate = null;

    //   if ((!this.__TaskStart && task.Start) || (this.__TaskStart && task.Start && this.__TaskStart.getTime() != task.Start.getTime())) {
    //     task.ConstraintType = 4; //不得早于...开始
    //     task.ConstraintDate = new Date(task.Start.getTime());
    //   }
    // } else if (!task.ConstraintDate) {
    //   if (task.ConstraintType == 2 || task.ConstraintType == 4 || task.ConstraintType == 5) task.ConstraintDate = new Date(task.Start.getTime());
    //   if (task.ConstraintType == 3 || task.ConstraintType == 6 || task.ConstraintType == 7) task.ConstraintDate = new Date(task.Finish.getTime());
    // }

    return task
  },
  /// //////////////////
  getResources: function () {
    var data = this.dataProject.Resources || []
    return data
  },
  // 关联计划设备
  getPlequipment: function () {
    var data = this.dataProject.Plequipment || []
    return data
  },
  // 关联人员工种
  getPlanwork: function () {
    var data = this.dataProject.PlanWork || []
    return data
  },
  getDepartments: function () {
    var data = this.dataProject.Departments || []
    return data
  },
  getPrincipals: function () {
    var data = this.dataProject.Principals || []
    return data
  },
  getPrincipalsByDepartment: function (dept) {
    var psAll = this.getPrincipals()
    var ps = []
    for (var i = 0, l = psAll.length; i < l; i++) {
      var p = psAll[i]
      if (p.Department == dept) {
        ps.push(p)
      }
    }
    return ps
  },
  getTaskByID: function (taskID) {
    return this.project.getTaskByID(taskID)
  },
  getTaskByUID: function (taskUID) {
    return this.project.getTask(taskUID)
  },
  getResourceByUID: function (reUID) {
    return this.project.getResource(reUID)
  },
  getPWorkByUID: function (UID) {
    var r = {}
    this.dataProject.PlanWork.forEach(element => {
      if (element.UID == UID) {
        r = element
      }
    })
    return r
  },
  getPlequipmentByUID: function (UID) {
    var r = {}
    this.dataProject.Plequipment.forEach(element => {
      if (element.UID == UID) {
        r = element
      }
    })
    return r
  }
})
